package mylab.io.core.util;

import io.netty.channel.Channel;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
import lombok.experimental.UtilityClass;
import mylab.io.base.Das;

@UtilityClass
public class ChannelAttr {

    public final AttributeKey<Das> ATTR_DAS = AttributeKey.valueOf("DAS");

    public <T> T get(Channel channel, AttributeKey<T> attrKey) {
        return getAttribute(channel, attrKey).get();
    }

    public <T> void set(Channel channel, AttributeKey<T> attrKey, T t) {
        getAttribute(channel, attrKey).set(t);
    }

    public <T> Attribute<T> getAttribute(Channel channel, AttributeKey<T> key) {
        return channel.attr(key);
    }
}
